<template>
   <el-card>
      <!-- 教材管理 -->
      <bread-crumb slot="header">
        <template slot="title">教材管理</template>
      </bread-crumb>
      <div class="Contaner">
          <div class="QueryBtn">
            <el-select v-model="value" placeholder="请选择" style=" width: 170px;">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
            <el-input v-model="value1" placeholder="请输入内容" style="width: 210px;margin-left: 20px;"></el-input>
              <el-button @click="listTeachingMaterial(value)" style="margin-left: 20px; height: 25px; line-height: 3px;" type="primary">查询</el-button>
          </div>
        <el-tabs type="border-card">
          <el-tab-pane label="教材查询">
             <!-- <el-button @click="exportBounced = true" type="primary" style="margin-bottom: 16px; margin-top: 15px;">导出数据</el-button> -->
              <el-table :header-cell-style="{ background: '#eee', color: '#606266' }" :data="tableData"  max-height="450" style="width: 100%">
                <el-table-column label="教材名称" width="340%">
                  <template slot-scope="{row}">
                    <el-button
                    @click="textbook(row)"
                      type="text"
                      size="small">
                      {{row.name}}
                    </el-button>
                  </template>
                </el-table-column>
                <!-- servicesName  有问题待调整 -->
                <el-table-column label="所属机构" width="210%">
                  <template slot-scope="{row}">
                    <el-button
                       @click="$router.push('/home/organizationInfo')"
                      type="text"
                      size="small">
                      {{row.Principal}}
                    </el-button>
                  </template>
                </el-table-column>
                <el-table-column prop="typeName" label="教材类型" width="254%"></el-table-column>
                <el-table-column prop="press" label="出版社" width="254%"></el-table-column>
                <el-table-column prop="reviewDate" label="申报时间" width="210%">
                  <template slot-scope="{row}">
                    <p>
                      <!-- {{row.reviewDate}} -->
                      {{formatTime(row.reviewDate * 1000)}}
                    </p>
                  </template>
                </el-table-column>
              </el-table>
              <!-- 分页 -->
                <el-row
                  type="flex"
                  align="middle"
                  justify="end"
                  style="margin-top: 20px"
                >
                  <el-col :span="8">
                    <el-pagination
                      background
                      layout="total, prev, pager, next, sizes"
                      :total="page.total"
                      :page-sizes="[7, 10, 20, 50, 100]"
                      :page-size="page.pageSize"
                      @current-change="changePage"
                      @size-change="handleSizeChange"
                      :current-page.sync="page.currentPage"
                    ></el-pagination>
                  </el-col>
                </el-row>
          </el-tab-pane>
          <el-tab-pane label="教材审批">
            <div class="Selectionsss">
              <div class="left_btn">
               <el-button plain @click="listTeachingMaterial">全部</el-button>
               <el-button plain @click="listTeachingMaterial('待审批')">待审批</el-button>
               <el-button plain @click="listTeachingMaterial('已通过')">已通过</el-button>
               <el-button plain @click="listTeachingMaterial('未通过')">未通过</el-button>
              </div>
              <div class="right_shenhe" v-show="true">
                <el-button type="success" @click="doTeachingMaterialReview">批量通过</el-button>
                <el-button type="danger" @click="stipo">批量不通过</el-button>
              </div>
            </div>
              <el-table :header-cell-style="{ background: '#eee', color: '#606266' }" :data="tableData"  max-height="450" style="width: 100%"
              tooltip-effect="dark"
              @selection-change="handleSelectionChange"
              >
              <el-table-column type="selection" width="55"> </el-table-column>
                <el-table-column label="教材名称" width="170%">
                <template slot-scope="{row}">
                    <el-button
                    @click="textbook(row)"
                      type="text"
                      size="small">
                      {{row.name}}
                    </el-button>
                  </template>
                </el-table-column>
                <el-table-column label="所属机构" width="190%">
                <template slot-scope="{row}">
                    <el-button
                       @click="$router.push('/home/organizationInfo')"
                      type="text"
                      size="small">
                      {{row.Principal}}
                    </el-button>
                  </template>
                </el-table-column>
                <el-table-column prop="typeName" label="教材类型" width="170%"></el-table-column>
                <el-table-column prop="press" label="出版社" width="210%"></el-table-column>
                <el-table-column label="办件类型" width="150%">
                <template slot-scope="{row}">
                    <p>
                      {{row.reviewType === 'add' ? '新增' : '注销'}}
                    </p>
                  </template>
                </el-table-column>
                <el-table-column label="审批状态" width="150%">
                <template slot-scope="{row}">
                    <p>
                      {{row.reviewStatus === 0 ? '未通过' : row.reviewStatus === 1 ? '待审核' : '已通过'}}
                    </p>
                  </template>
                </el-table-column>
                <el-table-column prop="reviewDate" label="申报时间" width="170%">
                  <template slot-scope="{row}">
                    <p>
                      <!-- {{row.reviewDate}} -->
                      {{formatTime(row.reviewDate * 1000)}}
                    </p>
                  </template>
                </el-table-column>
              </el-table>
              <!-- 分页 -->
                <el-row
                  type="flex"
                  align="middle"
                  justify="end"
                  style="margin-top: 20px; margin-bottom: 20px;"
                >
                  <el-col :span="8">
                    <el-pagination
                      background
                      layout="total, prev, pager, next, sizes"
                      :total="page.total"
                      :page-sizes="[7, 10, 20, 50, 100]"
                      :page-size="page.pageSize"
                      @current-change="changePage"
                      @size-change="handleSizeChange"
                      :current-page.sync="page.currentPage"
                    ></el-pagination>
                  </el-col>
                </el-row>
          </el-tab-pane>

        </el-tabs>
      </div>
      <!-- 导出弹框 -->
      <el-dialog title="导出数据" width="500px" :visible.sync="exportBounced">
        <div class="ExportBtn">
          <el-button type="primary">导出当前页</el-button>
          <el-button style="margin-left: 60px" type="primary"
            >导出全部数据（搜索后）</el-button
          >
        </div>
      </el-dialog>
      <!-- 详细信息 -->
      <el-dialog title="详细信息" width="600px" :visible.sync="exportBouncedsssss">
        <div class="big_Info"><div>教材名称：</div><div style="margin-left: 2px;">{{ teaching.name }}</div></div>
        <div class="big_Info"><div>教材类型：</div><div style="margin-left: 2px;">{{ teaching.typeName }}</div></div>
        <div class="big_Info"><div>所属年纪：</div><div style="margin-left: 2px;">{{ teaching.gradeName }}</div></div>
        <div class="big_Info"><div>学科：</div><div style="margin-left: 2px;">{{ teaching.subjectName }}</div></div>
        <!-- <div class="big_Info"><div>教材使用时间：</div><div style="margin-left: 2px;">{{ teaching.reviewDate }}</div></div> -->
        <div class="big_Info"><div>教材使用时间：</div><div style="margin-left: 2px;">{{ formatTime(1637358090574) }}</div></div>
        <div class="big_Info"><div>课程教材说明：</div><div style="margin-left: 2px;">{{ teaching.instructions }}</div></div>
        <div class="big_Info"><div>出版社：</div><div style="margin-left: 2px;">莆田教育出版社</div></div>
        <div class="big_Info" style=" padding-bottom: 50px;">
          <div style="width: 140px;">教材备案：</div><div class="displieblok">
            <div class="itemImg">
              <el-image style="width: 190px; height:100px;" :src="`/api/v1/pri/util/showPic?fileId=${teaching.coverImgId}`" alt=""> </el-image>
              <div>封面</div>
            </div>
            <div class="itemImg">
              <el-image style="width: 190px; height:100px;" :src="`/api/v1/pri/util/showPic?fileId=${teaching.backImgId}`" alt=""> </el-image>
              <div>封底</div>
            </div>
            <div class="itemImg">
              <el-image style="width: 190px; height:100px;" :src="`/api/v1/pri/util/showPic?fileId=${teaching.catalogueImgId}`" alt=""> </el-image>
              <div>目录</div>
            </div>
            <div class="itemImg">
              <el-image style="width: 190px; height:100px;" :src="`/api/v1/pri/util/showPic?fileId=${teaching.publishImgId}`" alt=""> </el-image>
              <div>说明</div>
            </div>
          </div>
        </div>
      </el-dialog>
   </el-card>
</template>

<script>
import { listTeachingMaterial, doTeachingMaterialReview } from '@/api'
export default {
  data () {
    return {
      exportBouncedsssss: false,
      exportBounced: false,
      exportBouncedsss: false,
      options: [{
        value: '教材名称',
        label: '教材名称'
      }, {
        value: '出版社',
        label: '出版社'
      }, {
        value: '教材类型',
        label: '教材类型'
      }, {
        value: '所属机构',
        label: '所属机构'
      }],
      value: '',
      value1: '',
      page: {
        // 分页数据
        total: 1000, // 总条数
        currentPage: 1, // 默认的页码 是第一个页  决定了当前页码是第几页
        pageSize: 9 // page-size的默认值是10条
      },
      tableData: [
        {
          licence: '光明顶',
          Institutional: '王小虎', // 1
          InstitutionalType: '上海市普陀区',
          Organizers: '厉害陈', // 4
          Principal: '150', // 5
          licencessss: '通过' // 5
        },
        {
          licence: '光明顶',
          Licenceissued: '2016-05-02',
          Institutional: '王小虎',
          InstitutionalType: '上海市普陀区',
          Organizers: '厉害陈',
          Principal: '150',
          licencessss: '通过' // 5
        }
      ],
      teaching: {}
    }
  },
  created () {
    this.listTeachingMaterial()
  },
  methods: {
    // 批量拒绝
    stipo () {
      this.$prompt('请输入拒绝理由', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(async ({ value }) => {
        if (value === null || value === '') {
          this.$message({
            type: 'error',
            message: '请输入原因'
          })
          return false
        }
        const a = this.multipleSelection.map((item) => {
          return item.id
        })
        const data = {
          idList: a,
          reviewStatus: 0,
          reviewRemarks: value
        }
        const ser = await doTeachingMaterialReview(data)
        if (ser.code === 200) {
          this.$message.success(ser.msg)
          this.listTeachingMaterial()
        }
      })
    },
    // 批量通过
    async doTeachingMaterialReview () {
      const a = this.multipleSelection.map((item) => {
        return item.id
      })
      const data = {
        idList: a,
        reviewStatus: 2
      }
      const ser = await doTeachingMaterialReview(data)
      if (ser.code === 200) {
        this.$message.success(ser.msg)
        this.listTeachingMaterial()
      }
    },
    // 教材列表
    async listTeachingMaterial (type) {
      let data = {}
      switch (type) {
        case '教材名称':
          data = { name: this.value1.trim() }
          break
        case '出版社':
          data = { press: this.value1.trim() }
          break
        case '教材类型':
          data = { type: this.value1.trim() }
          break
        case '所属机构':
          data = { servicesName: this.value1.trim() }
          break
        case '待审批':
          data = { reviewStatus: 1 }
          break
        case '已通过':
          data = { servicesName: 2 }
          break
        case '未通过':
          data = { servicesName: 0 }
          break

        default:
          break
      }
      const ser = await listTeachingMaterial(data)
      if (ser.code === 200) {
        const { list, total } = ser.data
        this.tableData = list
        this.page.total = total
      }
    },
    // 当选择项发生变化时会触发该事件
    handleSelectionChange (val) {
      console.log('我选择了')
      console.log(val)
      this.multipleSelection = val
    },
    // 教材详情
    textbook (item) {
      this.teaching = item
      this.exportBouncedsssss = true
    },
    // 格式化 毫秒级时间戳 1637338090875
    formatTime (item) {
      return this.$formatTime(item)
    }
  }
}
</script>

<style lang="less" scopde>
  .Selectionsss {
    padding-top: 10px;
    padding-bottom: 26px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .left_btn {

      .el-button+.el-button {
        margin-left: 0;
    }
      }
  }
  .big_Info {
    display: flex;
    padding: 0 24px 16px;
    color: rgba(0,0,0,.85);
    .displieblok {
      display: flex;
      flex-wrap: wrap;
      .itemImg:nth-child(odd) {
        margin-bottom: 20px;
        margin-right: 20px;
      }
      .itemImg {
        width: 190px;
        height: 165px;
        div {
          text-align: center;
          line-height: 70px;
          border: 1px solid #f0f0f0;
        }
        img {
          width: 100%;
          height: 100px;
        }
      }
    }
  }
.Top_seach {
  .tabelskc {
    display: flex;
      margin-bottom: 24px;
    .shuru {
      width: 100%;
    }
    .left_name {
      width: 180px;
      height: 32px;
      text-align: right;
      line-height: 32px;
    }
  }
      .blocksss {
      padding: 0 0 0 75px;
      margin-bottom: 24px;
    }
  .category {
    padding: 0 0 0 20px;
    display: flex;
    align-items: center;
    margin-bottom: 24px;
    .checkboxs {
      width: 500px;
      display: flex;
      flex-wrap: wrap;
      .el-checkbox {
        margin-right: 15px;
      }
    }
  }
  p {
    margin-bottom: 10px;
    font-weight: 600;
    font-size: 20px;
    color: #000000;
  }
}
  .ExportBtn {
    width: 80%;
    margin: 0px 40px 0px;
    padding-bottom: 40px;
  }
  .el-card__body {
    padding: 0 !important;

      .el-dialog {
    margin-bottom: 0 !important;
  }

  .el-dialog__body {
    padding: 30px 20px 0;
    border-top: 1px solid #e4e4e4;
  }
  }
  .Contaner {
    position: relative;
  }
  .QueryBtn {
    display: flex;
    align-items: center;
    width: 550px;
    height: 40px;
    position: absolute;
    top: 0;
    right: 30px;
    z-index: 1;
    .el-input__suffix {
      line-height: 50px;
    }
    input {
      height: 30px;
    }
  }
</style>
